/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-01-24
 * Time: 20:46
 */
public class Sort {
    // 插入排序
    public static void insertSort(int[] array){
        for (int i = 1; i <array.length ; i++) {
            int tmp=array[i];
            int j=i-1;
            for (; j >=0 ; j--) {
                if(array[j]>tmp){
                    array[j+1]=array[j];
                }else{
                    array[j+1]=tmp;
                    break;
                }

            }
            array[j+1]=tmp;
        }


    }
    // 希尔排序
    public  void shellSort(int[] array){
        int gap=array.length/2;
        while(gap>=1){
            shell(array,gap);
            gap/=2;
        }
    }
    public void shell(int[] arr,int gap){
        int i=gap;

        for ( ;  i< arr.length; i++) {
            int tmp=arr[i];
            int j=i-gap;
            for ( ;j>=0;j-=gap){
                if(arr[j]>tmp){
                    arr[j+gap]=arr[j];
                }else{
                    arr[j+gap]=tmp;
                    break;
                }

            }
            arr[j+gap]=tmp;
        }

    }

}
